package com.qms.qep.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qms.common.core.controller.BaseController;
import com.qms.common.core.domain.AjaxResult;
import com.qms.common.core.page.TableDataInfo;
import com.qms.qep.domain.RepairOrder;
import com.qms.qep.service.IRepairOrderService;

/**
 * 维修工单Controller
 */
@RestController
@RequestMapping("/qep/repair-order")
public class RepairOrderController extends BaseController {
    @Autowired
    private IRepairOrderService repairOrderService;

    /**
     * 查询维修工单列表
     */
    @PreAuthorize("@ss.hasPermi('qep:repair-order:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairOrder repairOrder) {
        startPage();
        List<RepairOrder> list = repairOrderService.selectRepairOrderList(repairOrder);
        return getDataTable(list);
    }

    /**
     * 获取维修工单详细信息
     */
    @PreAuthorize("@ss.hasPermi('qep:repair-order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(repairOrderService.selectRepairOrderById(id));
    }
    
    /**
     * 根据缺陷记录ID查询维修工单
     */
    @PreAuthorize("@ss.hasPermi('qep:repair-order:query')")
    @GetMapping(value = "/defect-record/{defectRecordId}")
    public AjaxResult getInfoByDefectRecordId(@PathVariable("defectRecordId") Integer defectRecordId) {
        return success(repairOrderService.selectRepairOrderByDefectRecordId(defectRecordId));
    }

    /**
     * 新增维修工单
     */
    @PreAuthorize("@ss.hasPermi('qep:repair-order:add')")
    @PostMapping
    public AjaxResult add(@RequestBody RepairOrder repairOrder) {
        return toAjax(repairOrderService.insertRepairOrder(repairOrder));
    }

    /**
     * 修改维修工单
     */
    @PreAuthorize("@ss.hasPermi('qep:repair-order:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody RepairOrder repairOrder) {
        return toAjax(repairOrderService.updateRepairOrder(repairOrder));
    }

    /**
     * 删除维修工单
     */
    @PreAuthorize("@ss.hasPermi('qep:repair-order:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(repairOrderService.deleteRepairOrderByIds(ids));
    }
    
    /**
     * 统计维修工单数量
     */
    @PreAuthorize("@ss.hasPermi('qep:repair-order:query')")
    @GetMapping("/count")
    public AjaxResult count(RepairOrder repairOrder) {
        int count = repairOrderService.countRepairOrder(repairOrder);
        return success(count);
    }
} 